﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BitPortal.Models;
using BitPortal.Business;
using BitPortal.Utils;

namespace BitPortal.Modules.Statistic
{
    public partial class Statistic : Controls.BaseUserControl
    {
        public Models.Statistic CurrentStatistic { set; get; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            StatisticBLL.UpdateView(CurrentStatistic.StatisticID);
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            BindData();
        }

        protected void BindData()
        {
            ltrView.Text = CurrentStatistic.ViewCount.ToString();
            ltrLike.Text = CurrentStatistic.LikeCount.ToString();
            ltrDislike.Text = CurrentStatistic.DislikeCount.ToString();
        }
        protected void btnDislike_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                CurrentStatistic = StatisticBLL.UpdateLike(CurrentStatistic.StatisticID, -1, (bool)PortalConfigBLL.GetValueByName("Statistic.CheckCookie"), (bool)PortalConfigBLL.GetValueByName("Statistic.CheckUserID"));
                BindData();
            }
            catch (Exception ex)
            {
                (this.Page as Controls.BaseFrontendPage).ShowArlert(ex.Message);
            }
        }
        protected void btnLike_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                CurrentStatistic = StatisticBLL.UpdateLike(CurrentStatistic.StatisticID, 1, (bool)PortalConfigBLL.GetValueByName("Statistic.CheckCookie"), (bool)PortalConfigBLL.GetValueByName("Statistic.CheckUserID"));
                BindData();
            }
            catch (Exception ex)
            {
                (this.Page as Controls.BaseFrontendPage).ShowArlert(ex.Message);
            }
        }
    }
}